Skip to content

Merge FileImageDescriptor into URLImageDescriptor and clean it up #2899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

HannesWell
Copy link
Member

@HannesWell HannesWell commented Apr 9, 2025

In it's core the FileImageDescriptor queries the given context class for a resource at the given path and then operates on the returned URL or directly fetches the resource's stream. By optaining the resource's URL immediately and using an URLImageDescriptor with it a lot of similar code and logic from the FileImageDescriptor can be saved.

Additionally apply a few minor code clean-ups and remove a unused internal method.

@HannesWell HannesWell force-pushed the unify-ImageDescriptor-logic branch from e6c5232 to a1eada2 Compare April 9, 2025 17:58
@laeubi
Copy link
Contributor

laeubi commented Apr 9, 2025

Honestly this now feels it become completely unmaintainable and hardly understandable, can we not simply use an abstract base-class to share code instead of all this inlined lamda and hype-generic method calls?

Copy link
Contributor

github-actions bot commented Apr 9, 2025

Test Results

 1 523 files   -   301   1 523 suites   - 301   1h 15m 34s ⏱️ - 16m 26s
 7 918 tests ±    0   7 688 ✅  -     2  229 💤 +  1  0 ❌ ±0  1 🔥 +1 
22 184 runs   - 1 657  21 630 ✅  - 1 463  553 💤  - 195  0 ❌ ±0  1 🔥 +1 

For more details on these errors, see this check.

Results for commit 90ed170. ± Comparison against base commit 2e51edb.

This pull request skips 1 test.
UiTestSuite org.eclipse.ui.tests.api.ApiTestSuite org.eclipse.ui.tests.api.WorkbenchPluginTest ‑ testGetImageRegistryFromAdditionalDisplay

♻️ This comment has been updated with latest results.

@HannesWell
Copy link
Member Author

Honestly this now feels it become completely unmaintainable and hardly understandable, can we not simply use an abstract base-class to share code instead of all this inlined lamda and hype-generic method calls?

I'm not so sure if that becomes much simpler, but I can have a look.
Actually this was intended as up-front work to reduce the duplicated changes for #2593. But maybe it's simpler to complete that first and make this a follow-up. Then we also know better was is needed for that.

@HannesWell HannesWell marked this pull request as draft April 10, 2025 22:36
@HannesWell
Copy link
Member Author

While looking at both classes again I got the impression that actually the FileImageDescriptor class could be fully replaced by URLImageDescriptor. There are probably some corner cases that still have to be handled (e.g. resource not found), but in general I didn't saw reason to keep the FileImageDescriptor.
Do you or anybody else know one?

@HannesWell HannesWell force-pushed the unify-ImageDescriptor-logic branch from bd58803 to 1289fc9 Compare April 11, 2025 22:43
@HannesWell HannesWell changed the title Unify logic of FileImageDescriptor and URLImageDescriptor Merge FileImageDescriptor into URLImageDescriptor and clean it up Apr 11, 2025
@HannesWell
Copy link
Member Author

While looking at both classes again I got the impression that actually the FileImageDescriptor class could be fully replaced by URLImageDescriptor.

I have now taken this path further and didn't found a reason speaking against it. The tests should now pass as well.

@HannesWell HannesWell marked this pull request as ready for review April 11, 2025 23:08
@HannesWell HannesWell force-pushed the unify-ImageDescriptor-logic branch 2 times, most recently from 3d2506d to 1f8f8eb Compare April 15, 2025 17:22
@HannesWell
Copy link
Member Author

This contains now much less, i.e. just one additional lambda in the zoom-image computation and is, from my side, ready for submission.
Does anybody want to review this?
If there are no objection respectively to request for more time to review, I plan to submit this tomorrow.

Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this simplification. I did not check in detail whether everything the FileImageDescriptor did is properly captured by the URLImageDescriptor as well. So far, I just found one place where I am not sure if behavior is properly preserved.

If you want me to do a more in-depth review, let me know, but I am not sure how soon I will find the time for it. So from my side, feel free to further process this PR if you are confident that everything works as expected.

@HannesWell HannesWell force-pushed the unify-ImageDescriptor-logic branch from 1f8f8eb to fddf7c8 Compare April 18, 2025 17:30
@HannesWell HannesWell force-pushed the unify-ImageDescriptor-logic branch 2 times, most recently from 5e07d2c to 1ce2520 Compare April 24, 2025 17:30
@HannesWell
Copy link
Member Author

Thank you for your review. Then I think this is ready for submission.
Nevertheless I have extracted the simplification part out into a separate PR

With that only a few a few changes remain in URLImageDescriptor for this change.

Once we have at least one working build I plan to submit this.

In it's core the FileImageDescriptor queries the given context class for
a resource at the given path and then operates on the returned URL or
directly fetches the resource's stream. By obtaining the resource's URL
immediately and using an URLImageDescriptor with it a lot of similar
code and logic from the FileImageDescriptor can be saved.

Additionally apply a few minor code clean-ups and remove a unused
internal method.
@HannesWell HannesWell force-pushed the unify-ImageDescriptor-logic branch from 1ce2520 to 90ed170 Compare April 26, 2025 19:02
@HannesWell HannesWell merged commit 6bb99bb into eclipse-platform:master Apr 26, 2025
9 of 11 checks passed
@HannesWell HannesWell deleted the unify-ImageDescriptor-logic branch April 26, 2025 21:05
@HeikoKlare
Copy link
Contributor

@HannesWell Are you aware that this change introduced a test failure in FileImageDescriptorTest? That test fails in every PR since this one was merged and it's also reproducible locally that this change introduced the failure. It was also reported by the according checks for this for 😉 https://github.com/eclipse-platform/eclipse.platform.ui/runs/41211453350

@HannesWell
Copy link
Member Author

HannesWell commented Apr 27, 2025

Are you aware that this change introduced a test failure in FileImageDescriptorTest? That test fails in every PR since this one was merged and it's also reproducible locally that this change introduced the failure.

My bad, I oversaw that and confused it with the other intermittent test-failure. Sorry and thanks for the heads-up.
Just created a fix to handle the kind of illegal files passed in in that test:

basilevs added a commit to eclipse-rcptt/org.eclipse.rcptt that referenced this pull request May 4, 2025
@basilevs
Copy link
Contributor

basilevs commented May 4, 2025

* [Merge FileImageDescriptor into URLImageDescriptor and clean it up #2899 (comment)](https://github.com/eclipse-platform/eclipse.platform.ui/pull/2899#issuecomment-2833461917)

The link is broken.

PS. RCPTT tests also broke due to changed ImageDescriptor representations. Users have to recapture Table/Tree verifications. Nothing can be done to avoid or fix this situation, because RCPTT effectively relies on ImageDescriptor.toString() which is an implementation detail.

@HannesWell
Copy link
Member Author

The link is broken.

It was indeed the wrong link, just fixed it.

PS. RCPTT tests also broke due to changed ImageDescriptor representations. Users have to recapture Table/Tree verifications. Nothing can be done to avoid or fix this situation, because RCPTT effectively relies on ImageDescriptor.toString() which is an implementation detail.

That's indeed unfortunate. But as you said, the exact result of toString() is not specified and one should not rely on it to have a specific value. If you think it's worth it and you can propose a simple fix to somehow restore the the result, we could 'fix' that.

@basilevs
Copy link
Contributor

If you think it's worth it

It is not. An application can change icons in its UI at any release and that's effectively what happened. Testing tools comparing icons should not pretend, than nothing has changed, so test failures are expected.

I only mention the problem for context, so that bigger picture is more visible.

@ptziegler
Copy link
Contributor

If you think it's worth it

It is not. An application can change icons in its UI at any release and that's effectively what happened. Testing tools comparing icons should not pretend, than nothing has changed, so test failures are expected.

I only mention the problem for context, so that bigger picture is more visible.

Clients will likely have to update their tests anyway, due to the migration from PNGs to SVGs. So I think having both changes in a single release is actually good thing.

For example, this is an error now reported by our test suite:

Line 79: verify-true: Assertion of cells[4].image.path failed: expected:<...full/obj16/warn_tsk.png> but was:<...full/obj16/warn_tsk.svg>.

@laeubi
Copy link
Contributor

laeubi commented May 16, 2025

By the way previously we have used the Adapter Pattern to gather additional information.

e.g. Adapters.of(imageDescriptor, URL.class) would be much bettern than rely on a artificial toString ..

@basilevs
Copy link
Contributor

basilevs commented May 16, 2025

By the way previously we have used the Adapter Pattern to gather additional information.

e.g. Adapters.of(imageDescriptor, URL.class) would be much bettern than rely on a artificial toString ..

Unless the adapter is implemented by JFace, it is no better than direct downcast. And downcast requires internal API access. toString() was used to avoid use of internal APIs.

I see that adapter was added in 2022, but RCPTT still supports Eclipse Platform 2019-03, which makes the approach non-universal.

@laeubi
Copy link
Contributor

laeubi commented May 16, 2025

I see that adapter was added in 2022, but RCPTT still supports Eclipse Platform 2019-03, which makes the approach non-universal.

This does not mean one could try it first and then fallback to the old approach...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants